<?php

namespace app\site\controller\traits;

use app\common\exception\MiException;
use app\Request;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;

trait CurdTrait
{

    /**
     * @throws DbException
     */
    public function index(){
        return $this->reqSer->setService($this->service)->setPaginate()->getResponse();
    }

    /**
     * @throws MiException
     */
    public function add(){
        return $this->reqSer->setService($this->service)->add()->getResponse();
    }

    /**
     * @throws DataNotFoundException
     * @throws ModelNotFoundException
     * @throws DbException
     * @throws MiException
     */
    public function edit(Request $request){
        if($request->isPost()){
            return $this->reqSer->setService($this->service)->edit()->getResponse();
        }else{
            return $this->reqSer->setService($this->service)->setFind()->getResponse();
        }
    }

    /**
     * @throws DataNotFoundException
     * @throws ModelNotFoundException
     * @throws DbException
     * @throws MiException
     */
    public function del(){
        return $this->reqSer->setService($this->service)->delete()->getResponse();
    }
}
